#define xuser mixc::powerful_cat
#include"lang/cxx/encode_first_as.hpp"
#include"lang/cxx.hpp"
#include"mixc.hpp"

xinit(xuser::the_main){
    using namespace xuser;

    // 编码第一个字符
    // 由于是 ascii 字符，所以字符仍是它本身
    auto v0             = c08{"hello world!"}.encode_first_as<char/*char to char*/>();
    xhint(v0->is_success, v0);

    // 注意：
    // 不要假定 unicode 字符一定只有 3 个字节，实际标准上它可以多达 6 个字节
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    auto v1             = c08{"你好世界"}.encode_first_as<char>();
    xhint(v1->is_success, v1.ptr());

    // 将 utf-8 字符编码成 utf-16
    auto && the_love        = c08{"以爱之名"};
    auto && the_wide_love   = c16{u"以爱之名"};
    auto && understand      = c08{};

    while(understand != the_love){
        auto word0          = the_love.encode_first_as<char>();
        auto word1          = the_love.encode_first_as<char16_t>();

        auto word2          = the_wide_love.encode_first_as<char>();
        auto word3          = the_wide_love.encode_first_as<char16_t>();

        xhint(word0.ptr(), word2.ptr());
        xhint(word1, word3);

        the_love            = the_love.backward(word0->length);
        the_wide_love       = the_wide_love.backward(word3->length);
    }
};
